import Taro from '@tarojs/taro'

/**
 * 获取本地缓存
 * @param key
 * @returns
 */
export function getStorage(key) {
  return Taro.getStorageSync(key)
}

/**
 * 设置本地缓存
 * @param key
 * @param data
 * @returns
 */
export function setStorage(key,data = {}) {
  return new Promise(async (resolve,reject)=>{
    await Taro.setStorage({ key, data,
      success:function(res){
        resolve(res)
      },
      fail:function(err){
        reject(err)
      }
    })
  })
}

/**
 * 删除指定缓存
 * @param key
 * @returns
 */
export function removeStore(key){
  return new Promise(async (resolve,reject)=>{
    await Taro.removeStorage({ key,
      success:function(res){
        resolve(res)
      },
      fail:function(err){
        reject(err)
      }
    })
  })
}

/**
 * 清除本地缓存
 * @returns
 */
export async function clearStore(){
  await Taro.clearStorage()
}

